package models

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"usered/appconfig"
)

type Userrd struct {
	Id    int    `json:"id"`
	Name  string `json:"name"`
	Score string `json:"score"`
	Wei   string `json:"wei"`
	Ri    string `json:"ri"`
	Zt    string `json:"zt"`
}

var DB *gorm.DB

func Init() {
	confmysql := appconfig.Appconf.Mysql
	var err error
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", confmysql.User, confmysql.Password, confmysql.Host, confmysql.Port, confmysql.Database)
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	DB.AutoMigrate(&Userrd{})
}
